package beans;

import java.util.ArrayList;
import java.util.List;

import models.Album;
import models.Photo;
import models.User;

public class AlbumBean {
	public String title;
	public String url;
	public int workNum;
	public String albumId;
	public String authorName;
    public String info;
	public static AlbumBean bulid(Album album)
	{
		AlbumBean bean = new AlbumBean();
		bean.title = album.title;
        bean.workNum = album.articleNum;
        bean.albumId = album.id;
        bean.info = album.info;
        bean.authorName = User.getAuthorNameById(album.authorId);
        Photo photo = Photo.find("id = ?",album.photoId).first();
        if(photo!=null) {
            bean.url = photo.getPhoto();
        }
        else{
            bean.url = "";
        }
		return bean;
	}
	
	public static List<AlbumBean> bulidList(List<Album> albumlist){
		List<AlbumBean> albumBeanList = new ArrayList<AlbumBean>();
		for(int item =0 ; item < albumlist.size(); item ++){
			Album album = albumlist.get(item);
			AlbumBean albumbean = AlbumBean.bulid(album);
			albumBeanList.add(albumbean);
		}
		return albumBeanList;
	}
}
